﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DevFx.Model;
using DevFx.Web.Code;
using DevFx.Biz;

namespace DevFx.Web
{
    public partial class Index : System.Web.UI.Page
    {
        private string content = "";
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                
            }
        }
        public void getList()
        {
            var list = MenuBiz.GetMenuList();
            GetNodeList(list, Guid.Empty);
            Response.Write(content);
        }
        private void GetNodeList(List<SysMenu> List, Guid ParentID)
        {
            List<SysMenu> list = List.FindAll(delegate(SysMenu m) { return m.ParentID == ParentID; });
            foreach (SysMenu item in list)
            {
                if (item.Level.Value == 1)
                {
                    content += " <div title='" + item.Name + "' class='l-scroll'> ";
                    content += "<ul class='tree1' style='margin-top:3px;'>";
                    GetNodeList(List, item.MenuID);
                    content += " </ul></div>";
                }
                else if (item.Level.Value == 2)
                {
                    List<SysMenu> level2Menu = List.FindAll(delegate(SysMenu m) { return m.ParentID == item.MenuID; });
                    if (level2Menu.Count != 0)
                    {
                        content += "  <li isexpand='false'><span>" + item.Name + "</span><ul>  ";
                        GetNodeList(List, item.MenuID);
                        content += " </ul></li>";
                    }
                    else
                    {
                        
                        content += "<a class='l-link' href=\"javascript:f_addTab('listpage','"+item.Name+"','"+item.Url+"')\">"+item.Name+"</a>";
                        //content += "<a class='l-link' onclick='f_addTab( 'listpage','" + item.Name + "','" + item.Url + "');' href='#'>" + item.Name + "</a>";
                    }
                }
                else if (item.Level.Value == 3)
                {
                    content += "  <li url='" + item.Url + "'><span>" + item.Name.Trim() + "</span></li> ";
                }
            }
        }
    }
}